package zth.com.kotlindemo

import SunStarUtils.GlideUtil
import SunStarUtils.UtilBox
import SunStarView.RecycleViewDivider
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.widget.LinearLayoutManager
import android.widget.AdapterView
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
import zth.com.kotlindemo.adapter.MainMenuAdapter
import zth.com.kotlindemo.data.MenuData
import zth.com.kotlindemo.presenter.MainPresenter
import zth.com.kotlindemo.view.MainView

class MainActivity : AppCompatActivity() ,MainView{
    var menuDataList = mutableListOf<MenuData>()
    var presenter : MainPresenter?=null
    var fragmentList = mutableListOf<android.support.v4.app.Fragment>()
    var nameText ="阳光下的小喵"
    var menuAdapter : MainMenuAdapter? = null
    var imgUrl = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=396825656,2785281393&fm=23&gp=0.jpg"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        presenter = MainPresenter(this)
        presenter!!.initMain(menuDataList,fragmentList)
    }


    override fun initView() {
        //设置顶部栏为自定义顶部栏
        setSupportActionBar(main_toolbar)
        //设置返回键可用
        supportActionBar!!.setHomeButtonEnabled(true)
        supportActionBar!!.setDisplayHomeAsUpEnabled(true)
        var drameToggle = ActionBarDrawerToggle(this,main_menu_layout,main_toolbar,R.string.menu_open,R.string.menu_close)
        drameToggle.syncState()
        main_menu_layout.setDrawerListener(drameToggle)
        menuAdapter = MainMenuAdapter(this,menuDataList)
        var linearManager = LinearLayoutManager(this)
        menuAdapter!!.itemClickListener = AdapterView.OnItemClickListener { adapterView, view, i, l ->
            Toast.makeText(this,menuDataList.get(i).name,Toast.LENGTH_SHORT).show()
        }
        main_menu_rec.addItemDecoration(RecycleViewDivider(this,LinearLayoutManager.HORIZONTAL))
        main_menu_rec.adapter = menuAdapter
        main_menu_rec.layoutManager = linearManager
        GlideUtil.ShowCircleImg(this,imgUrl,main_avater)
        main_name.text = nameText
        main_time.text = UtilBox.getDataStr(System.currentTimeMillis(),"yyyy-MM-dd")
    }

    /**
     * 设置菜单
     */
    override fun loadMenu() {
        menuAdapter!!.notifyDataSetChanged()
    }

    /**
     * 设置标签页
     */
    override fun loadFragment() {
    }

    /**
     * 修改页面
     */
    override fun changePage(page: Int) {
    }

}

